// TODO：游戏开始
function start() {
    const startButton = document.getElementById('start');
    startButton.style.display = 'none';
    const moveButton = document.getElementById('move');
    moveButton.style.display = 'block';
}
let nowArea = 1; // 当前区域
const lumpAll = document.querySelectorAll('.lump');
const lump1All = document.querySelectorAll('.lump1');
const lump2All = document.querySelectorAll('.lump2');
let stepAll = lumpAll.length + lump1All.length + lump2All.length;

// TODO：重置游戏
function reset() {
    lumpAll[0].classList.add('active');
    lump2All[lump2All.length - 1].classList.remove('active');
    const resetButton = document.getElementById('reset');
    resetButton.style.display = 'none';
    const startButton = document.getElementById('start');
    startButton.style.display = 'block';
    const number = document.querySelector('.process input');
    number.value = '';
    const result = document.querySelector('.result');
    result.innerHTML = '';
    nowArea = 1;
}
// TODO：移动
function move() {
    const number = document.querySelector('.process input');
    const result = document.querySelector('.result');
    let step = 0; // 移动步数
    if (number.value == '') step = 0;
    else step = parseInt(number.value);
    if (step == 1 || step == 2) {
        result.innerHTML = "";
        // console.log("移动");
        nowArea += step;
        // console.log(nowArea);
        if (nowArea == 13) {
            lump1All.forEach((item) => {
                item.classList.remove('active');
            })
            lump1All[4].classList.add('active');
            result.innerHTML = "哎呀！兔子踩到炸弹了，游戏结束！";
            const moveButton = document.getElementById('move');
            moveButton.style.display = 'none';
            const resetButton = document.getElementById('reset');
            resetButton.style.display = 'block';
        } else if (nowArea >= stepAll) {
            lump2All.forEach((item) => {
                item.classList.remove('active');
            })
            lump2All[lump2All.length - 1].classList.add('active');
            result.innerHTML = "小兔子吃到胡萝卜啦，游戏获胜！";
            const moveButton = document.getElementById('move');
            moveButton.style.display = 'none';
            const resetButton = document.getElementById('reset');
            resetButton.style.display = 'block';
        } else {
            if (nowArea <= lumpAll.length) {
                lumpAll.forEach((item, index) => {
                    item.classList.remove('active');
                    if (nowArea == index + 1) {
                        item.classList.add('active');
                    }
                });
            } else if (nowArea <= lumpAll.length + lump1All.length) {
                lumpAll.forEach((item) => {
                    item.classList.remove('active');
                })
                lump1All.forEach((item, index) => {
                    item.classList.remove('active');
                    if (nowArea == lumpAll.length + index + 1) {
                        item.classList.add('active');
                    }
                })
            } else {
                lump1All.forEach((item) => {
                    item.classList.remove('active');
                })
                lump2All.forEach((item, index) => {
                    item.classList.remove('active');
                    if (nowArea == lumpAll.length + lump1All.length + index + 1) {
                        item.classList.add('active');
                    }
                })
            }
        }

    } else result.innerHTML = "输入的步数不正确，请重新输入。";

}